package club.vann.kafka.mock.service.perp;

import club.vann.kafka.mock.kafka.KafkaProducer;
import club.vann.kafka.mock.kafka.KafkaTopicFactory;
import com.cyberx.lunyu.PerpPairInventory;
import java.util.Random;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

@RequiredArgsConstructor
@Service
public class PerpetualService {
  private static final Random RANDOM = new Random();
  private final KafkaProducer kafkaProducer;

  public void pairSummary() {
    String pair = "BINANCE_PERP_BTC_USDT-BITGET_PERP_BTC_USDT";
    PerpPairInventory.PairInventoty pairInventoty =
        PerpPairInventory.PairInventoty.newBuilder()
            .setPair(pair)
            .setLeg1AvgPrice(RANDOM.nextDouble())
            .setLeg1MktPrice(RANDOM.nextDouble() * 60000.0D)
            .setLeg1Qty(RANDOM.nextDouble())
            .setLeg2AvgPrice(RANDOM.nextDouble())
            .setLeg2MktPrice(RANDOM.nextDouble() * 60000.0D)
            .setLeg2Qty(RANDOM.nextDouble())
            .setMktSpread(RANDOM.nextDouble() * 30.0D)
            .setPairedAvgSpread(RANDOM.nextDouble())
            .setPairedDirection(
                PerpPairInventory.PairInventoty.Direction.forNumber(RANDOM.nextInt(2)))
            .setPairedAmount(RANDOM.nextDouble())
            .setPairedQty(RANDOM.nextDouble())
            .setPairedUnrealizedPnl(RANDOM.nextDouble())
            .setUnPairedAmount(RANDOM.nextDouble())
            .setUnPairedAvgPrice(RANDOM.nextDouble())
            .setUnPairedDirection(
                PerpPairInventory.PairInventoty.Direction.forNumber(RANDOM.nextInt(2)))
            .setUnPairedSide(
                PerpPairInventory.PairInventoty.UnPairedSide.forNumber(RANDOM.nextInt(2)))
            .setUnPairedQty(RANDOM.nextDouble())
            .setUnPairedUnrealizedPnl(RANDOM.nextDouble())
            .setUnPairedPriceDiffBps(RANDOM.nextDouble())
            //            .setUnrealizedPnl(RANDOM.nextDouble())
            .setRealizedPnl(RANDOM.nextDouble())
            .setTimestamp(System.currentTimeMillis())
            .build();
    this.kafkaProducer.send(
        KafkaTopicFactory.PERP_PAIR_SUMMARY_OUTPUT, pair, pairInventoty.toByteArray());
  }
}
